package com.fieldchain.ex.fa100.utils.chart.utils.zb;

import android.graphics.Color;

import com.fieldchain.ex.fa100.bean.kline.KLineBean;
import com.fieldchain.ex.fa100.bean.kline.MACDEntity;
import com.fieldchain.ex.fa100.utils.chart.dataset.MyBarDataSet;
import com.fieldchain.ex.fa100.utils.chart.dataset.MyBarEntry;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/16
 */
public class MacdParse {
    private int c1 = Color.parseColor("#ffcc00");
    private int c2 = Color.parseColor("#0090f7");
    private int c3 = Color.parseColor("#ffffff");

    public CombinedData getData(List<List<String>> list) {
        ArrayList<KLineBean> datas = ZbDataParse.getKlineList(list);
        MACDEntity macdEntity = new MACDEntity(datas);
        List<MyBarEntry> macdBar = new ArrayList<>();
       ArrayList macdData = new ArrayList<>();
        ArrayList  deaData = new ArrayList<>();
        ArrayList difData = new ArrayList<>();
        for (int i = 0; i < macdEntity.getMACD().size(); i++) {
            MyBarEntry entry = new MyBarEntry(i, macdEntity.getMACD().get(i));
            entry.setClose(datas.get(i).getClose());
            entry.setOpen(datas.get(i).getOpen());
            macdBar.add(entry);
            macdData.add(entry);
            deaData.add(new Entry(i, macdEntity.getDEA().get(i)));
            difData.add(new Entry(i, macdEntity.getDIF().get(i)));
        }
        MyBarDataSet barDataSet = new MyBarDataSet(macdBar, macdData, "");

        BarData barData = new BarData(barDataSet);
        barData.setBarWidth(0.7f);

        LineData lineData = new LineData();
        LineDataSet lineSet1 = new LineDataSet(deaData, "");
        LineDataSet lineSet2 = new LineDataSet(difData, "");
        initLindata(lineSet1, c1);
        initLindata(lineSet2, c2);

        lineData.addDataSet(lineSet1);
        lineData.addDataSet(lineSet2);


        CombinedData combinedData = new CombinedData();
        combinedData.setData(barData);
        combinedData.setData(lineData);
        return combinedData;
    }

    public void initLindata(LineDataSet dataSet, int color) {
        dataSet.setColor(color);
        dataSet.setHighlightEnabled(false);
        dataSet.setHighlightLineWidth(1f);
        dataSet.setHighLightColor(c3);
        dataSet.setDrawValues(false);
    }



}
